package com.dycx.food.enums;

import lombok.AllArgsConstructor;
import lombok.Getter;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 订单类型
 */
@Getter
@AllArgsConstructor
public enum OrderTypeEnum {

    DEFAULT(1, "普通订单"),
    GROUP_PURCHASE(2, "团购订单");

    private final Integer code;
    private final String name;


    public static OrderTypeEnum getCode(Integer code) {
        for (OrderTypeEnum enums : OrderTypeEnum.values()) {
            if (enums.getCode().equals(code)) {
                return enums;
            }
        }
        return null;
    }

    /**
     * 转为列表
     *
     * @return 枚举对象数组
     */
    public static List<Map<String, String>> getList() {
        List<Map<String, String>> list = new ArrayList<>();
        for (OrderTypeEnum item : OrderTypeEnum.values()) {
            Map<String, String> map = new HashMap<>();
            map.put("code", item.getCode().toString());
            map.put("name", item.getName());
            list.add(map);
        }
        return list;
    }
}
